package com.ruoyi.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.enums.SignShortEnums;
import com.ruoyi.business.vo.TRegisterUserSign;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.business.domain.TRegisterSign;
import com.ruoyi.business.vo.TRegisterSignVo;
import com.ruoyi.business.mapper.TRegisterSignMapper;
import com.ruoyi.business.service.ITRegisterSignService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 签署告知书信息Service业务层处理
 *
 * @author Tellsea
 * @date 2025-03-25
 */
@Service
public class TRegisterSignServiceImpl extends ServiceImpl<TRegisterSignMapper, TRegisterSign> implements ITRegisterSignService {

    @Override
    public TableDataInfo<TRegisterSignVo> queryList(TRegisterSignVo entity) {
        return PageUtils.buildDataInfo(this.baseMapper.queryList(PageUtils.buildPage(), entity));
    }

    @Override
    public List<TRegisterSignVo> queryAll(TRegisterSignVo entity) {
        return this.baseMapper.queryList(entity);
    }

    @Override
    public TRegisterSignVo queryById(String uuid) {
        return this.baseMapper.queryById(uuid);
    }

    @Override
    public TRegisterSign getSignByKind(TRegisterSignVo entity) {
        QueryWrapper<TRegisterSign> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("register_id",entity.getRegisterId());
        queryWrapper.eq("sign_short",entity.getSignShort());
        List<TRegisterSign> tRegisterSigns = this.baseMapper.selectList(queryWrapper);
        if(tRegisterSigns!=null && !tRegisterSigns.isEmpty()){
            return tRegisterSigns.get(0);
        }
        return null;
    }

    @Override
    public List<TRegisterSign> getKXBatchNoSign(TRegisterUserSign entity) {
        QueryWrapper<TRegisterSign> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("register_id",entity.getRegisterIdList());
        queryWrapper.eq("sign_type", 2);
        queryWrapper.eq("sign_other_status", 0);
        queryWrapper.eq("sign_self_status", 1);
        if(StringUtils.isNotEmpty(entity.getSignerRole())){
            queryWrapper.eq("sign_short", entity.getSignerRole());
        }
        return this.baseMapper.selectList(queryWrapper);
    }


}
